package 链表;

/**
 * https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
 */
public class _160_相交链表 {

    //双指针，人工造一个环
    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode slow = headA, fast = headB;

        while (slow != fast) {
            slow = slow == null ? fast : slow.next;
            fast = fast == null ? slow : fast.next;
        }

        return slow;
    }
}
